using System.Collections;
using Lucene.Net.Analysis;
using Lucene.Net.QueryParsers;
using NHibernate;
using NHibernate.Search;
using NUnit.Framework;
using Wikey.Entity;

namespace Wikey.Tests
{

    [TestFixture]
    public class SearchTest : TestCase
    {
        [SetUp]
        public void Setup()
        {
            session = _sessionFactory.OpenSession();
        }
        
        [TearDown]
        public void TearDown()
        {

        }

        private ISession session;

        [Test]
        public void ExecuteTest()
        {

            IFullTextSession s = Search.CreateFullTextSession(session);

            var newPage =
                new Page
                {
                    Id = 0,
                    FriendlyName = "MySearchQueryTest",
                    Name = "My Search Query Test"
                };

            s.Save(newPage);
            s.Clear();

            var queryParser = new QueryParser("id", new StopAnalyzer());

            IQuery NHQuery = s.CreateFullTextQuery(
                queryParser.Parse("Name:Search or Name:Test") , typeof(ContentNode));

            IList result = NHQuery.List();

            Assert.AreEqual(2 , result.Count );
        }


    }

}
